#记录登录日志
import time
def show_info():
    print('输入数字提示相应操作：0退出，1查看日志')

def login_log(username):
    with open('log.txt', 'a',encoding='utf-8') as f:
        s = f'用户名：{username},登录时间：{time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(time.time()))}'
        f.write(s)
        f.write('\n')

def read_log():
    with open('log.txt', 'r', encoding='utf-8') as f:
        while True:
            line = f.readline()
            if  line == '':
                break
            else:
                print(line)

if __name__ == '__main__':
    # login_log('admin')
    username = input('请输入用户名')
    password = input('请输入密码')
    if username == 'admin' and password == 'admin':
        print('登录成功')
        login_log(username)
        show_info()
        num = eval(input('请输入要操作的数字：'))
        while True:
            if num == 0:
                print('退出成功')
                break
            elif num == 1:
                print('查看登录日志')
                read_log()
                show_info()
            else:
                print('输入数字有误')
                show_info()
            num = eval(input('请输入要操作的数字：'))
    else:
        print('用户名或密码不正确')